﻿using System;
using System.Collections.Generic;
using System.Text;

namespace iNet
{
	/// <summary>
	/// 提供作業系統相關資訊。
	/// </summary>
	public static class OperatingSystemInfo
	{
		#region 欄位
		static OperatingSystemFlags _Flags;
		static Version _Version;
		static string _VersionString;
		#endregion
		#region 型別建構子
		static OperatingSystemInfo()
		{
			//取得版本
			OperatingSystem os = Environment.OSVersion;
			_Version = os.Version;
			_VersionString = os.VersionString;
			
			//取得 Windows 版本
			if (os.Platform == PlatformID.Win32NT)
			{
				_Flags |= OperatingSystemFlags.IsWindowsNT;
				if (_Version.Major >= 5)
					_Flags |= OperatingSystemFlags.IsWindowsXPOrAbove;
				if (_Version.Major >= 6)
				{
					_Flags |= OperatingSystemFlags.IsWindowsVistaOrAbove;
					if (_Version.Minor >= 1)
						_Flags |= OperatingSystemFlags.IsWindows7OrAbove;
				}
			}
		}
		#endregion
		#region Flags
		/// <summary>
		/// 取得作業系統旗標。
		/// </summary>
		public static OperatingSystemFlags Flags
		{
			get
			{
				return _Flags;
			}
		}
		#endregion
		#region Version
		/// <summary>
		/// 取得作業系統版本。
		/// </summary>
		public static Version Version
		{
			get
			{
				return _Version;
			}
		}
		#endregion
		#region VersionString
		/// <summary>
		/// 取得作業系統版本字串。
		/// </summary>
		public static string VersionString
		{
			get
			{
				return _VersionString;
			}
		}
		#endregion
	}
	#region OperatingSystemFlags
	/// <summary>
	/// 表示作業系統相關旗標。
	/// </summary>
	[Flags]
	public enum OperatingSystemFlags
	{
		/// <summary>
		/// Windows NT 系列。
		/// </summary>
		IsWindowsNT = 0x1,
		/// <summary>
		/// Windows XP 以上。
		/// </summary>
		IsWindowsXPOrAbove = 0x100,
		/// <summary>
		/// Windows Vista 以上。
		/// </summary>
		IsWindowsVistaOrAbove = 0x200,
		/// <summary>
		/// Windows 7 以上。
		/// </summary>
		IsWindows7OrAbove = 0x400,
	}
	#endregion
}
